<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Representantes
 *
 * @author ETorres
 * @export Modules
 */
class Representantes extends Module {
    
    public function index() {
        $representantesQuery = $this->model->RepresentantesData->getRepresentantes();
        
        $representantes = array();
        
        foreach ($representantesQuery as $representante) {
            $student = $this->model->students->GetById($representante["codigo_estudiante"]);
            
            $rep = array();
            
            array_push($rep, $student->getNombres(). " " .$student->getApellidos());
            array_push($rep, $student->getCodigoEstudiante());
            array_push($rep, $student->getPlanEstudio()->getNombrePlan());
            array_push($rep, $representante['aprobado']);
            array_push($rep, $representante['tipoCandidatura']);
            
            array_push($representantes, $rep);
        }
        
        $this->assign("representantes", $representantes);
        $this->assign("verRepresentante", $this->route->action("verRepresentante"));
        $this->display();
    }
    
    public function verRepresentante() {
        
        $codigoEstudiante = $this->request->get("CodigoEstudiante");
        
        $student = $this->model->students->GetById($codigoEstudiante);
        
        $representante = $this->model->RepresentantesData->GetRepresentanteByCodigo($codigoEstudiante);
        
        
        $this->assign("estudiante", $student);
        $this->assign("representante", $representante);
        $this->assign("regresar", $this->route->action("index"));
        $this->assign("action", $this->route->action("responder"));
        $this->display();
        
    }
    
    public function responder() {
        
        $codigoEstudiante = $this->request->post("codigoEstudiante");
        $respuesta = $this->request->post("respuesta");
        
        if($respuesta == 'true'){
            $respuesta = 1;
        }else{
            $respuesta = 0;
        }
        
        $this->model->RepresentantesData->responder($codigoEstudiante, $respuesta);
        
        $this->addMessage(new Message("¡Respuesta enviada satisfactoriamente!", "", Message::SUCCESS));
        $this->assign("regresar", $this->route->action("index"));
        $this->display();
        
    }
}

?>
